package com.bsoft.gol.hcs.clinical.dao;


import com.bsoft.gol.hcs.clinical.bean.req.NavigationSettingReq;
import com.bsoft.gol.hcs.clinical.entity.NavigationListSettings;
import ctd.persistence.support.hibernate.HibernateSupportDelegateDAO;
import ctd.persistence.support.hibernate.template.AbstractHibernateStatelessResultAction;
import ctd.persistence.support.hibernate.template.HibernateSessionTemplate;
import ctd.persistence.support.hibernate.template.HibernateStatelessResultAction;
import org.hibernate.SQLQuery;
import org.hibernate.StatelessSession;
import com.bsoft.gol.hcs.utils.CommonUtils;

import java.util.List;

public abstract class NavigationListSettingsDAO extends HibernateSupportDelegateDAO<NavigationListSettings> {
    public List<NavigationListSettings>  queryNavigationListSettings(final NavigationSettingReq req) {
        HibernateStatelessResultAction<List<NavigationListSettings> > action =
                new AbstractHibernateStatelessResultAction<List<NavigationListSettings> >() {
                    @Override
                    public void execute(StatelessSession ss) throws Exception {
                        StringBuffer stringBuffer = new StringBuffer();
                        stringBuffer.append(" select * from navigation_list_settings WHERE 1=1  ");
                        if (CommonUtils.isNotEmpty(req.getHospitalCode())) {//医院CODE
                            stringBuffer.append(" and hospital_code = '" + req.getHospitalCode() + "' ");
                        }
                        if (CommonUtils.isNotEmpty(req.getModuleCode())) {//医院CODE
                            stringBuffer.append(" and module_code = '" + req.getModuleCode() + "' ");
                        }
                        if (CommonUtils.isNotEmpty(req.getGuideCode())) {//医院CODE
                            stringBuffer.append(" and guide_code = '" + req.getGuideCode() + "' ");
                        }
                        if (CommonUtils.isNotEmpty(req.getModuleStatus())) {//医院CODE
                            stringBuffer.append(" and module_status = '" + req.getModuleStatus() + "' ");
                        }
                        SQLQuery sqlQuery = ss.createSQLQuery(stringBuffer.toString());
                        sqlQuery.addEntity(NavigationListSettings.class);
                        setResult(sqlQuery.list());
                    }
                };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }


}
